package com.satan.fmmall.controller;

import com.satan.fmmall.entity.ShoppingCart;
import com.satan.fmmall.service.ShoppingCartService;
import com.satan.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @ClassName ShopingCartController
 * @Description TODO
 * @date 2022/4/12 21:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/shopcart")
@Api(tags = "购物车管理",value = "提供购物车业务相关接口")
public class ShopingCartController {
    @Resource
    private ShoppingCartService shoppingCartService;
    @ApiOperation("添加购物车接口")
    @PostMapping("/add")
    public ResultVo addShoppingCart(@RequestBody ShoppingCart shoppingCart){
        System.out.println(shoppingCart);
        return shoppingCartService.addShoppingCart(shoppingCart);
    }
    @ApiOperation("购物车列表查询接口")
    @GetMapping("/list")
    public ResultVo list(Integer userId){
        return shoppingCartService.listShoppingCartsByUserId(userId);
    }
    @ApiOperation("更新购物车商D品数量接口")
    @PostMapping("/update/{cid}/{cnum}")
    public ResultVo updateNum(@PathVariable("cid") Integer cartId,@PathVariable("cnum") Integer cartNum){
        return shoppingCartService.updateCartNum(cartId,cartNum);
    }
    @ApiOperation("删除购物车商品接口")
    @DeleteMapping("/delete")
        public ResultVo deleteShopCart(@RequestBody Integer[] cartIds){
        System.out.println("cartIds = " + Arrays.toString(cartIds));
        ResultVo resultVo = shoppingCartService.deleteShopCartByCartId(cartIds);
        return resultVo;
    }
    @ApiOperation("根据商品Id查询购物车商品接口")
    @GetMapping("/list-by-cartid")
    public ResultVo listByCartId(Integer[] cartIds){
        System.out.println(Arrays.toString(cartIds));
        return shoppingCartService.listShoppingCartsByCartIds(cartIds);
    }
}
